/**
 * Created by webrx on 2017-09-27.
 */

$(function () {
    var phone = false;
    var pwd = false;
    var pwd1 = false;
    var yzm = false;
    var tiaokuan = false;

    //手机号验证
    $("#reg_mobile_").blur(function(){
        var val = $("#reg_mobile_");//手机
        var tip = $("#reg_mobile_tip");//提示标签
        var regexp_mobile=/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0-9]|17[0-9])\d{8}$/;
        if (regexp_mobile.test(val.val())){
            $.ajax({
                url:"/user/checkphone",
                type: "post",
                cache: false,
                async: true,
                data:{ phone:val.val() },
                dataType: "text",
                success: function(b){
                    if (b==0){
                        tip.html("该用户可以注册");
                        tip.css("color","green");
                        phone = true;
                    } else {
                        tip.html("该用户已被注册");
                        tip.css("color","red");
                    }
                }
            })
        }else {
            tip.html("用户名错误!");
            tip.css("color","red");
        }

    });

    //验证码
    $("#code2_").blur(function(){
        var ma = $("#code2_").val();//验证码
        var tip = $("#code2_tip");//提示标签
        if(ma.length<4){
            tip.html("验证码格式错误");
            tip.css("color","red");
        } else {
            $.ajax({
                url:"/user/checkout",
                type: "post",
                cache: false,
                async: true,
                data:{ maV:ma },
                dataType: "text",
                success: function(b){
                    if(b==1){
                        tip.html("验证码正确");
                        tip.css("color","green");
                        yzm = true;
                    } else {
                        tip.html("验证码有误");
                        tip.css("color","red");
                    }
                }
            })
        }

    });

    //密码
    $("#reg_password_").blur(function(){
        var val = $("#reg_password_");//密码
        var tip = $("#reg_password_tip1");//提示标签
        var regexp_password=/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~\`\[\]\{\}\;\:\'\"\,\<\.\>\/\?\-\_\=\+\(\)\|\\]{6,25}$/;
        if (regexp_password.test(val.val())){
            tip.html("密码符合要求!");
            tip.css("color","green");
            pwd = true;
        } else {
            tip.html("密码不符合要求，密码应6-25位之间!");
            tip.css("color","red");
        }
    });

    //确认密码
    $("#reg_password2").blur(function(){
        var val = $("#reg_password2");//密码
        var tip = $("#reg_password_tip2");//提示标签
        if (val.val() == $("#reg_password_").val()){
            tip.html("密码一致!");
            tip.css("color","green");
            pwd1 = true;
        } else {
            tip.html("两次密码不一致!");
            tip.css("color","red");
        }
    });

    //阅读交易条款
    if($('#rules')[0].checked){
        tiaokuan = true;
    } else {
        $("#ruleTips").html("请阅读交易条款");
        $("#ruleTips").css("color","red");
    }

    //提交
    $("#reg_buton").click(function () {
        if (pwd && phone && pwd1 && yzm && tiaokuan){
        } else {
            $("#registerform").attr("action","#");
        }
    })


})